package by.msokoloff.javaweb2015.webapp.page.planemodel;

import javax.inject.Inject;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;

import by.msokoloff.javaweb2015.datamodel.PlaneModel;
import by.msokoloff.javaweb2015.services.PlaneModelService;
import by.msokoloff.javaweb2015.webapp.page.EntityListPage;

public class PlaneModelForm extends Form<PlaneModel> {

	@Inject
	private PlaneModelService planeModelService;

	private PlaneModel planeModel;

	public PlaneModelForm(String id, IModel<PlaneModel> model) {
		super(id, model);
		add(new Label("id"));
		add(new TextField<String>("name"));
		add(new TextField<String>("iataCode"));
		add(new TextField<Integer>("capacity"));
		add(new TextField<Double>("speed"));
		add(new TextField<Double>("fuelConsumption"));
				
		add(new FeedbackPanel("feedbackpanel"));
		planeModel = model.getObject();
	}

	@Override
	public final void onSubmit() {
		planeModelService.createOrUpdate(planeModel);
		setResponsePage(new EntityListPage(PlaneModel.class));
	}

	@Override
	public final void onError() {
		System.out.println("Error!");
	}
}
